﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Build.Utilities;
using Microsoft.Build.Framework;
using System.Diagnostics;

namespace Bewise.SharePoint.WebPartator.Tasks
{
    public class WebPartator : ToolTask
    {


        protected override string ToolName
        {
            get { return "WebPartator.exe"; }
        }

        protected override string GenerateFullPathToTool()
        {
            return this.WebPartatorDir + @"\WebPartator.exe";
        }

        public string TargetPath
        {
            get;
            set;
        }

        public string Assembly
        {
            get;
            set;
        }

        protected override string GenerateCommandLineCommands()
        {
            CommandLineBuilder builder = new CommandLineBuilder();

            builder.AppendFileNameIfNotNull(this.Assembly);
            builder.AppendFileNameIfNotNull(this.TargetPath);

            return builder.ToString();
        }

        public string WebPartatorDir
        {
            get;
            set;
        }
    }

    public class AspNetMerge : ToolTask
    {

        protected override string ToolName
        {
            get { return "aspnet_merge.exe"; }
        }
        protected override string GenerateFullPathToTool()
        {
            return @"C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\aspnet_merge.exe";
        }

        public string KeyFile { get; set; }

        protected override string GenerateCommandLineCommands()
        {
            CommandLineBuilder builder = new CommandLineBuilder();
            builder.AppendSwitch(this.TargetPath);
            builder.AppendSwitchIfNotNull("-o ", this.AssemblyName);
            builder.AppendSwitchIfNotNull("-keyfile ", this.KeyFile);
            return builder.ToString();
        }

        public string TargetPath
        {
            get;
            set;
        }

        public string AssemblyName
        {
            get;
            set;
        }



    }

    public class IlMerge : ToolTask
    {
        protected override string GenerateFullPathToTool()
        {
            return @"C:\Program Files\Microsoft\ILMerge\IlMerge.exe";
        }

        protected override string ToolName
        {
            get { return "IlMerge.exe"; }
        }

        public string TargetPath
        {
            get;
            set;
        }

        public string KeyFile
        {
            get;
            set;
        }

        public string PreCompiled
        {
            get;
            set;
        }

        public string NonPreCompiled
        {
            get;
            set;
        }

        protected override string GenerateCommandLineCommands()
        {
            CommandLineBuilder builder = new CommandLineBuilder();
            builder.AppendSwitchIfNotNull("/out:", this.TargetPath);
            builder.AppendSwitch("/t:library");
            builder.AppendSwitch(this.PreCompiled);
            builder.AppendSwitch(this.NonPreCompiled);
            builder.AppendSwitchIfNotNull("/keyfile:", this.KeyFile);
            return builder.ToString();
        }
    }

    public class StrongName : ToolTask
    {
        protected override string GenerateFullPathToTool()
        {
            return @"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\sn.exe";
        }

        public string KeyFile
        {
            get;
            set;
        }
        public string TargetPath
        {
            get;
            set;
        }

        protected override string GenerateCommandLineCommands()
        {
            CommandLineBuilder builder = new CommandLineBuilder();
            builder.AppendSwitch("-R");
            builder.AppendSwitch(this.TargetPath);
            builder.AppendFileNameIfNotNull(this.KeyFile);
            return builder.ToString();
        }

        protected override string ToolName
        {
            get { return "sn.exe"; }
        }
    }
}
